package com.example.programexpert

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge

import android.graphics.Color


class MainActivity : ComponentActivity() {
    private val expert = ProgramExpert()

    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        setContentView(R.layout.layout)

        val spinner = findViewById<Spinner>(R.id.spinner2)
        val button = findViewById<Button>(R.id.button3)
        val textView = findViewById<TextView>(R.id.textView2)
        button.setBackgroundColor(Color.YELLOW)

        button.setOnClickListener {
            textView.text = expert.getLanguage(spinner.selectedItem.toString())
        }


        val dynamicContainer: LinearLayout = findViewById(R.id.dynamic_texts)
        val buttonAddText: Button = findViewById(R.id.button4)

        buttonAddText.setOnClickListener {
            val count = dynamicContainer.childCount + 1

            val newTextView = TextView(this).apply {
                text = "This is a new TextView: $count"
                textSize = 16f
                setTextColor(Color.MAGENTA)
                setBackgroundColor(Color.CYAN)
                setPadding(16, 12, 16, 12)
            }

            dynamicContainer.addView(newTextView)
        }
    }
}